# Contributor: Celeste <cielesti@protonmail.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-cohttp
pkgver=5.3.1
pkgrel=0
_pkgreal=cohttp
pkgdesc="Library for HTTP clients and servers"
url="https://github.com/mirage/ocaml-cohttp"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-base64-dev
	ocaml-conduit-dev
	ocaml-fmt-dev
	ocaml-logs-dev
	ocaml-lwt-dev
	ocaml-magic-mime-dev
	ocaml-ppx_sexp_conv-dev
	ocaml-uri-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	ocaml-cmdliner-dev
	ocaml-jsonm-dev
	"
checkdepends="
	ocaml-alcotest-dev
	ocaml-ounit-dev
	"
options="!check" # requires unpackaged crowbar
subpackages="
	$pkgname-dev
	$pkgname-tools
	"
source="$_pkgreal-$pkgver.tar.bz2::https://github.com/mirage/ocaml-cohttp/releases/download/v$pkgver/cohttp-$pkgver.tbz"
builddir="$srcdir/$_pkgreal-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --verbose \
		-p cohttp,cohttp-top,cohttp-lwt,cohttp-lwt-unix
}

check() {
	dune runtest --build-dir=.testenv --verbose \
		-p cohttp,cohttp-top,cohttp-lwt,cohttp-lwt-unix
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit \
		cohttp cohttp-top cohttp-lwt cohttp-lwt-unix
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

tools() {
	pkgdesc="$pkgdesc (command line utilities)"
	depends=

	amove usr/bin
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
26580405fc33cd7e05b2c91732df97da9ba609d7392e5779be601aa65e34f1991d2b0ae2870ac29e57567f583dc0e13e61d3c4a74c7ac21012453acb33a37ae3  cohttp-5.3.1.tar.bz2
"
